package sf.r2dbc.handle;

import io.r2dbc.spi.Result;
import reactor.core.publisher.Flux;
import sf.r2dbc.rowmapper.R2dbcRowMapper;
import sf.r2dbc.sql.R2dbcResultSetCallback;

/**
 * 单一值回调处理
 * @param <T>
 */
public class R2dbcSingleRowHandler<T> implements R2dbcResultSetCallback<T> {

    private R2dbcRowMapper<T> mapper;

    public R2dbcSingleRowHandler(R2dbcRowMapper<T> mapper) {
        this.mapper = mapper;
    }

    @Override
    public Flux<T> callback(Flux<Result> resultFlux) {
        return resultFlux.flatMap(r -> r.map(mapper));
    }
}
